package com.sen.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Kisen
 * @email lqs0911@qq.com
 * @date 2022/11/19 16:43
 * @detail 订单确认页需要用的数据
 */
public class OrderConfirmVo {

    //收获地址
    @Getter
    @Setter
    private List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter
    @Setter
    private List<OrderItemVo> items;

    //发票信息...

    //优惠券信息...
    @Getter
    @Setter
    private Integer integration;

    //防重令牌
    @Getter
    @Setter
    private String orderToken;

    @Getter
    @Setter
    private Map<Long, Boolean> stocks;

    public Integer getCount() {
        Integer count = 0;
        if (CollectionUtils.isNotEmpty(items)) {
            count = items.size();
        }
        return count;
    }

    //private BigDecimal total; //订单总额
    public BigDecimal getTotal() {
        BigDecimal sum = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //private BigDecimal payPrice; //应付价格
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
